//
//  TBUser.swift
//  新浪微博
//
//  Created by bin on 16/1/29.
//  Copyright © 2016年 XMG. All rights reserved.
//

import UIKit

class TBUser: NSObject {

    /// 用户昵称
    var screen_name: String?
    
    /// 用户头像地址（中图），50×50像素
    var profile_image_url: String?{
        didSet{
          avatarURL = NSURL(string: profile_image_url!)
        }
    }

    /// 会员等级 1~6
    var mbrank: Int = -1{
        didSet{
            if mbrank>=1 && mbrank<=6{
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)") 
            }
        }
    }
    
    /// 认证类型 -1：没有认证，0，个人认证，2,3,5: 企业认证，220: 达人
    var verified_type: Int = -1{
        didSet{
            switch verified_type {
            case -1 :
                verifiedImage = nil
            case 0 :
                verifiedImage = UIImage(named: "avatar_vip")
            case 2,3,5 :
                verifiedImage = UIImage(named: "avatar_enterprise_vip")
            case 220 :
                verifiedImage = UIImage(named: "avatar_grassroot")
            default :
                TBLog("verified_type other")
            }
        }
    }

    /// 用户头像URL
    var avatarURL: NSURL?
    
    /// 认证图片
    var verifiedImage: UIImage?
    
    /// 会员图片
    var mbrankImage: UIImage?
    
    init(dict: [String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    // 如果利用KVC赋值, 但是字典和模型的属性不能一一对应, 就会调用下面这个方法
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    // 只要重写这个属性, 就相当于OC中重写description方法
    override var description: String {
        // 优化
        let property = ["screen_name", "profile_image_url", "mbrank", "verified_type"]
        let dict =  dictionaryWithValuesForKeys(property)
        return "\(dict)"
    }
    // （模型中属性为模型）KVC的setValuesForKeysWithDictionary方法内部会调用下面这个方法
    


}
